/*****************************************************************
* Avetis Petrosyan
* Rolando Douglas
* ECE 625
* Project Digital Scoreboard
* General commands to the 68HCS12 along with functions to simplify
* interfacing with the DRAGON12+ board
******************************************************************/

#ifndef COMMANDS_H
#define COMMANDS_H

#define LCD_DATA PORTK
#define LCD_CTRL PORTK
#define RS 0x01
#define EN 0x02       
#define RS_COMMAND_MODE 0
#define RS_DATA_MODE 1
#define MAX_LCD_SIZE 16
#define LINE_1 0
#define LINE_2 1
#define CURSOR_LINE 0
#define CURSOR_INDEX 1
#define SHIFT_RIGHT_CMD 0x14
#define SHIFT_LEFT_CMD 0x10
#define SHIFT_WORD_LEFT_CMD 0x18
#define SHIFT_WORD_RIGHT_CMD 0x1C
#define NO_PADDING 0
#define ZERO_PADDING 1
#define UPDATE_MIN 1
#define BASE_ON_PREV_MIN 0
#define TIE_GAME 1
                    
#define MIN_INDEX 11
#define SEC_INDEX 14

#define TEAM_SCORE_INDEX 4

void MSDelay(unsigned int itime);
void CmdToLCD(unsigned char _ucCommand, unsigned char _ucRS);
void InitializeLCD(void);
void ClearLCD(void);
void InitializeVariables(void);
void SetCursorLine(unsigned char _ucLine);
void SetCursorIndex(unsigned char _ucIndex);
void UpdateCursorPos(unsigned char _ucLine, unsigned char _ucIndex);
void SetCursorPosition(unsigned char _ucLine, unsigned char _ucIndex);
void WriteString(unsigned char *_ucString, unsigned char _ucLine, unsigned char _ucIndex);
void WriteChar(unsigned char _ucNum, unsigned char _ucLine, unsigned char _ucIndex);
void WriteNumber(unsigned char _ucNum, unsigned char _ucLine, unsigned char _ucIndex, unsigned char _ucZeroPadding);
void WriteGoal(int _nTime, unsigned char *_ucaTeam);
void WriteGoal7SegLED(int _nTime);
void WriteNoGoal7SegLED(int _nTime);
void WriteNoGoal(int _nTime, unsigned char *_ucaTeam);
void WriteTime(unsigned char _ucMin, unsigned char *_ucPrevMin, unsigned char _ucWriteMin, unsigned char _ucSec);   
void DecreaseTime(unsigned char *_ucTime);
int DetermineWinner(unsigned char *_ucaTeam1, unsigned char *_ucaTeam2, unsigned char _ucTeam1Score, unsigned char _ucTeam2Score);
void ShiftWords(unsigned char _ucShift);

#endif /* COMMANDS_H */
